#ifndef _SOCKETDEFS_HPP_
#define _SOCKETDEFS_HPP_

#include "platform.hpp"

#define JH_ENOERR 0
#define JH_HAVE_IPv6

#ifdef JH_OS_WINDOWS
	#include <winsock2.h>
	#include <ws2tcpip.h>
	#define JH_SOCKET SOCKET
	#define JH_INVALID_SOCKET INVALID_SOCKET
	#define JH_SOCKETLEN int
	#define JH_CLOSESOCKET(s) closesocket(s)

	#ifndef ADDRESS_FAMILY
		#define ADDRESS_FAMILY USHORT
	#endif

	#define JH_EINTR           WSAEINTR
	#define JH_EACCES          WSAEACCES
	#define JH_EFAULT          WSAEFAULT
	#define JH_EINVAL          WSAEINVAL
	#define JH_EMFILE          WSAEMFILE
	#define JH_EAGAIN          WSAEWOULDBLOCK
	#define JH_EWOULDBLOCK     WSAEWOULDBLOCK
	#define JH_EINPROGRESS     WSAEINPROGRESS
	#define JH_EALREADY        WSAEALREADY
	#define JH_ENOTSOCK        WSAENOTSOCK
	#define JH_EDESTADDRREQ    WSAEDESTADDRREQ
	#define JH_EMSGSIZE        WSAEMSGSIZE
	#define JH_EPROTOTYPE      WSAEPROTOTYPE
	#define JH_ENOPROTOOPT     WSAENOPROTOOPT
	#define JH_EPROTONOSUPPORT WSAEPROTONOSUPPORT
	#define JH_ESOCKTNOSUPPORT WSAESOCKTNOSUPPORT
	#define JH_ENOTSUP         WSAEOPNOTSUPP
	#define JH_EPFNOSUPPORT    WSAEPFNOSUPPORT
	#define JH_EAFNOSUPPORT    WSAEAFNOSUPPORT
	#define JH_EADDRINUSE      WSAEADDRINUSE
	#define JH_EADDRNOTAVAIL   WSAEADDRNOTAVAIL
	#define JH_ENETDOWN        WSAENETDOWN
	#define JH_ENETUNREACH     WSAENETUNREACH
	#define JH_ENETRESET       WSAENETRESET
	#define JH_ECONNABORTED    WSAECONNABORTED
	#define JH_ECONNRESET      WSAECONNRESET
	#define JH_ENOBUFS         WSAENOBUFS
	#define JH_EISCONN         WSAEISCONN
	#define JH_ENOTCONN        WSAENOTCONN
	#define JH_ESHUTDOWN       WSAESHUTDOWN
	#define JH_ETIMEDOUT       WSAETIMEDOUT
	#define JH_ECONNREFUSED    WSAECONNREFUSED
	#define JH_EHOSTDOWN       WSAEHOSTDOWN
	#define JH_EHOSTUNREACH    WSAEHOSTUNREACH
	#define JH_ESYSNOTREADY    WSASYSNOTREADY
	#define JH_ENOTINIT        WSANOTINITIALISED
	#define JH_HOST_NOT_FOUND  WSAHOST_NOT_FOUND
	#define JH_TRY_AGAIN       WSATRY_AGAIN
	#define JH_NO_RECOVERY     WSANO_RECOVERY
	#define JH_NO_DATA         WSANO_DATA

#elif defined JH_OS_LINUX

	#define JH_SOCKET int
	#define JH_INVALID_SOCKET -1
	#define JH_SOCKETLEN socklen_t
	#define JH_CLOSESOCKET(s) close(s)

	#define JH_EINTR           EINTR
	#define JH_EACCES          EACCES
	#define JH_EFAULT          EFAULT
	#define JH_EINVAL          EINVAL
	#define JH_EMFILE          EMFILE
	#define JH_EAGAIN          EAGAIN
	#define JH_EWOULDBLOCK     EWOULDBLOCK
	#define JH_EINPROGRESS     EINPROGRESS
	#define JH_EALREADY        EALREADY
	#define JH_ENOTSOCK        ENOTSOCK
	#define JH_EDESTADDRREQ    EDESTADDRREQ
	#define JH_EMSGSIZE        EMSGSIZE
	#define JH_EPROTOTYPE      EPROTOTYPE
	#define JH_ENOPROTOOPT     ENOPROTOOPT
	#define JH_EPROTONOSUPPORT EPROTONOSUPPORT
	#define JH_ESOCKTNOSUPPORT ESOCKTNOSUPPORT
	#define JH_ENOTSUP         ENOTSUP
	#define JH_EPFNOSUPPORT    EPFNOSUPPORT
	#define JH_EAFNOSUPPORT    EAFNOSUPPORT
	#define JH_EADDRINUSE      EADDRINUSE
	#define JH_EADDRNOTAVAIL   EADDRNOTAVAIL
	#define JH_ENETDOWN        ENETDOWN
	#define JH_ENETUNREACH     ENETUNREACH
	#define JH_ENETRESET       ENETRESET
	#define JH_ECONNABORTED    ECONNABORTED
	#define JH_ECONNRESET      ECONNRESET
	#define JH_ENOBUFS         ENOBUFS
	#define JH_EISCONN         EISCONN
	#define JH_ENOTCONN        ENOTCONN
	#define JH_ESHUTDOWN       ESHUTDOWN
	#define JH_ETIMEDOUT       ETIMEDOUT
	#define JH_ECONNREFUSED    ECONNREFUSED
	#define JH_EHOSTDOWN       EHOSTDOWN
	#define JH_EHOSTUNREACH    EHOSTUNREACH
	#define JH_ESYSNOTREADY    -4
	#define JH_ENOTINIT        -5
	#define JH_HOST_NOT_FOUND  HOST_NOT_FOUND
	#define JH_TRY_AGAIN       TRY_AGAIN
	#define JH_NO_RECOVERY     NO_RECOVERY
	#define JH_NO_DATA         NO_DATA
#endif

#if !defined(s6_addr16)
	#if defined(JH_OS_WINDOWS)
		#define s6_addr16 u.Word
	#else
		#define s6_addr16 __u6_addr.__u6_addr16
	#endif
#endif

#if !defined(s6_addr32)
	#if defined(JH_OS_LINUX)
		#define s6_addr32 __u6_addr.__u6_addr32
	#endif
#endif

#define jh_set_sa_len(pSA, len) (void) 0
#define jh_set_sin_len(pSA)     (void) 0
#define jh_set_sin6_len(pSA)    (void) 0

#endif
